package com.hspjava.Arrays_;

import java.util.Arrays;
import java.util.Comparator;

public class ArrayExercise {
    public static void main(String[] args) {
        Book[] books = new Book[4];
        books[0] = new Book("hlm", 100);
        books[1] = new Book("jpm", 90);
        books[2] = new Book("qnwz", 5);
        books[3] = new Book("java", 300);
        Arrays.sort(books, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Book b1 = (Book)o1;
                Book b2 = (Book)o2;
                return (int) (b1.price - b2.price);
            }
        });

        System.out.println("===排序后===");
        System.out.println(Arrays.toString(books));
    }


}
class Book {
    public String name;
    public double price;

    public Book(String name, double price) {

        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}